package cn.tedu.oop;

public class TestConstructor2 {
    public static void main(String[] args) {
        //6.1使用无参构造创建对象s1
        Student s1 = new Student();
        //6.2使用含参构造创建对象s2,参数:哈哈哈
        Student s2 = new Student("哈哈哈");
        //6.3使用全参构造创建对象s3,参数:张三,男,抬杠,100
        Student s3 = new Student("张三1",'男',"抬杠",100);
        System.out.println(s1.name);
        System.out.println(s2.name);
        System.out.println(s3.name);
    }
}
//1.创建学生类Student
class Student{
    //2.提供学生类的属性:姓名name 性别gender 专业major 成绩score
    String name;
    char gender; //一个字符汉字
    String major;
    double score;
    //3.创建本类的无参构造
    public Student(){
        System.out.println("我是Student的无参构造"); //创建无参构造对象,同时打印方法体,就必须手动写包含打印语句的sout无参构造方法
    }
    //4.创建本类的含参构造(String s)
    public Student(String s){
        System.out.println("我是Student的含参构造"+s);
    }
    //5.创建本类的全参构造
    public Student(String name, char gender, String major, double score) {
        this.name = name;
        this.gender = gender;
        this.major = major;
        this.score = score;
        System.out.println("我是Student类的全参构造");
    }
}
